package Q5;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;

public class ChatServer {
    public static void main(String[] args) {
        ArrayList<Socket> socketList = new ArrayList<>();
        Socket socket = null;
        ServerSocket server = null;
        try {
            server = new ServerSocket(8889);
            while(true) {
                System.out.println("就绪等待请求");
                socket = server.accept();
                socketList.add(socket);
                System.out.println("接收到客户请求");
                new ServerThread(socket, socketList).start();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                assert server != null;
                server.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
